<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="<c:url value='/js/plug/area/load_area.js'/>"></script>
<%@ taglib prefix="se" uri="http://zc.security/acl"%>

<div id="cc_salesmans" class="easyui-layout" style="width:100%;height:100%;" fit="true">
	<div data-options="region:'north',title:'业务员',split:true" style="height:70px;background-color:#e6edfd;">
    	<form action="" id="searchForm" name="searchForm">
    	<table class="screen">
			<tr>
				<td class="screen-n"><span>姓名</span></td>
				<td class="screen-n">
					<input type="text" id="s_salesmanName" class="screen-input" style="width:200px"onkeydown="pms.kd13('initsalesmans')">
				</td>
				<td class="screen-n"><span>性别</span></td>
				<td class="screen-n">
				    <select name="salesmanSex" id="salesmanSex" style="width:80px;" class="easyui-combobox" panelheight="auto">
				       <option value="">全部</option>
					   <option value="1">男</option>
					   <option value="2">女</option>
				    </select>
				</td>
				<td class="screen-n"><span>类型</span></td>
				<td class="screen-n">
				    <select name="salesmanType" id="salesmanType" style="width:80px;" class="easyui-combobox" panelheight="auto">
				       <option value="">全部</option>
					   <option value="1">厂家业务员</option>
					   <option value="2">公司业务员</option>
				    </select>
				</td>
				<td class="screen-n"><span>是否可代理供应商</span></td>
				<td class="screen-n">
				    <select name="isAgentProvider" id="isAgentProvider" style="width:80px;" class="easyui-combobox" panelheight="auto">
				       <option value="">全部</option>
					   <option value="0">否</option>
					   <option value="1">是</option>
				    </select>
				</td>
				<td class="screen-n">
					<input type="button" class="button" value="查询" onclick="initsalesmans()">
					<input type="button" class="button" value="重置" onclick="pms.resetForm('searchForm')" >
					<input type="button" class="button" value="导出" onclick="loadExecl('initStoreOutCheckTableExcel')" >
				</td>
			</tr>
		</table>
		</form>
    </div>
    <div data-options="region:'center',split:true" style="width: 100%;height: 100%">
		<table id="tableGrid"></table>
	</div>
</div>  
<script>

var toolbar = [
<se:hasPermissions actCode="ADD" >        
{
	text:'业务员录入',
    iconCls:'ext-icon-note_add',
    handler:function(){
    	openSalesmanAddWindow();
    }
},
</se:hasPermissions>       
<se:hasPermissions actCode="DELETE" >
{
	text:'业务员删除',
    iconCls:'ext-icon-note_delete',
    handler:function(){
    	var rows = salesmansTable.getCheckedData();
		if(rows==null || rows.length==0){
			alertWarning("请选中要删除的数据!");
			return;
		}
		if(confirm("确定批量删除?")){
			var ids = [];
			for(var i=0; i<rows.length; i++){
				ids.push(rows[i].salesmanId);
			}
			var salesmanIdList = ids.toString();
			var param = {"salesmanIdList":salesmanIdList};
			$.pmsAjax({
				url:'<c:url value="/salesman/deleteMultipleEmBSalesmans.do"/>',
				data:param,
				success:function(data){
					if(data.code=="200"){
						alertShow("批量删除成功！");
						salesmansTable.refresh();
					}else{
						alertError(data.result);
					}
				}
			});
		}
    }
}
</se:hasPermissions>
];
var salesmansTable;
$(function(){
	initsalesmans();
});
function getParams(){
	var queryParamss = {
			"salesmanName":$('#s_salesmanName').val(), 
			"salesmanSex":$('#salesmanSex').combobox('getValue'),
			"salesmanType":$('#salesmanType').combobox('getValue'),
			"isAgentProvider":$('#isAgentProvider').combobox('getValue')
	    };
    return queryParamss;
}
function initsalesmans(){
	salesmansTable = $('#tableGrid').pDataGrid({
		toolbar:toolbar,
		columns:[[
				   {field:'ck',checkbox:true},
	               {field:'salesmanName',title:'姓名',align:'center'},
	               {field:'salesmanSex',title:'性别',align:'center',formatter:function(value){
						if(value=="1"){
							return '男';
						}else{
							return '女';
						}
		           }},
		           {field:'salesmanType',title:'业务员类型',align:'center',formatter:function(value){
						if(value=="1"){
							return '厂家业务员';
						}else{
							return '公司业务员';
						}
		           }},
		           {field:'mobile',title:'手机',align:'center'},
	               {field:'phone',title:'座机',align:'center'},
	               {field:'email',title:'邮箱',align:'center'},
	               {field:'qq',title:'QQ',align:'center'},
	               {field:'salesmanNative',title:'祖籍',align:'center'},
	               {field:'department',title:'部门编码',align:'center'},
	               {field:'duty',title:'职务',align:'center'},
		           {field:'joinDate',title:'加入日期',align:'center'},
	               {field:'modifyPrice',title:'修改权限',align:'center',formatter:function(value){
						if(value=="1"){
							return '可修改价格';
						}else if(value=="2"){
							return '可选批号';
						}else if(value=="3"){
							return '可修改价格和批号';
						}else if(value=="4"){
							return '可调配送价';
						}else{
							return '';
						}
		           }},
		           {field:'isAgentProvider',title:'是否可代理供应商',align:'center',formatter:function(value){
						if(value=="0"){
							return '否';
						}else if(value=="1"){
							return '是';
						}else{
							return '';
						}
		           }},
		           {field:'addBuyer',title:'身份代理选择',align:'center',formatter:function(value){
		        	    if(value=="1"){
							return '所有客户';
						}else if(value=="2"){
							return '所属客户';
						}else{
							return '';
						}
		           }},
		           {field:'action',title : '操作',align : 'center',
						formatter : function(value, row, index) {
							var str = '';
							<se:hasPermissions actCode="UPDATE" > 
								str += ' <img class="iconImg ext-icon-note_edit" title="编辑" onclick="openSalesmanUpdateWindow('+row.salesmanId+');"/>';
							</se:hasPermissions>   
								
							<se:hasPermissions actCode="MAINTAIN" >
								str += ' <img class="iconImg ext-icon-user_add" title="添加用户" onclick="addSalesmanUserWindow('+row.salesmanId+');"/>';
								str += ' <img class="iconImg ext-icon-user_red" title="设置所属供应商" onclick="fetchBelongProvider(\''+row.salesmanId+'\');"/>';
								str += ' <img class="iconImg ext-icon-user_green" title="设置所属采购商" onclick="fetchBelongBuyer(\''+row.salesmanId+'\');"/>';
							</se:hasPermissions> 
							<se:hasPermissions actCode="DELETE" >
								str += ' <img class="iconImg ext-icon-note_delete" title="删除" onclick="deleteSalesman('+row.salesmanId+',' + index + ');"/>';
							</se:hasPermissions> 
								return str;
						}
					} 
		          ]],
		    url:'<c:url value="/salesman/searchPageSalesman.do" />',  
		    pagination:true,//分页控件
		    pageSize:30,
		    singleSelect:false,
		    rownumbers:true,
		    queryParams:getParams(),
			onDblClickRow:function(index,row){
				openSalesmanUpdateWindow(row.salesmanId);
			}
		    
	}); 
}

function openSalesmanAddWindow(){
	$.pmsDialog({
		id:"w_salesman_add",
		title:'新增业务员',
		isIf:'true',
		fit:true,
		method:'post',
		href:'<c:url value="/views/jsp/customer/salesman/salesman_detail.jsp"/>',
		width:900,
		height:600
	});
}
 function openSalesmanUpdateWindow(code){
	var params = {"code":code};
	$.pmsDialog({
		id:"w_salesman_update",
		title:'修改业务员',
		isIf:'true',
		fit:true,
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/customer/salesman/salesman_detail.jsp"/>',
		width:900,
		height:600
	}); 
}
function addSalesmanUserWindow(code){
	var params = {"code":code};
	$.pmsDialog({
		id:"w_adduser",
		title:'添加用户',
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/customer/salesman/salesman_adduser_s.jsp"/>',
		width:550,
		height:500
	}); 
}
function deleteSalesman(code,i){
	if(confirm("确定删除?")){
		var param = {"salesmanId":code};
		$.pmsAjax({
			url:'<c:url value="/salesman/deleteSalesman.do"/>',
			data:param,
			success:function(data){
				if(data.code=="200"){
					alertShow("删除成功");
					salesmansTable.refresh();
				}else{
					alertError(data.result);
				}
			}
		});
	}
}
//获取归属客户列表
function fetchBelongProvider(salesmanId){
	var params = {"salesmanId":salesmanId};
	$.pmsDialog({
		id:"w_salesman_provider_list",
		title:'已添加所属供应商',
		isIf:'true',
		fit:true,
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/customer/salesman/salesman_provider_list.jsp"/>',
		width:800
	}); 
}
//获取归属客户列表
function fetchBelongBuyer(salesmanId){
	var params = {"salesmanId":salesmanId};
	$.pmsDialog({
		id:"w_salesman_buyer_list",
		title:'已添加所属采购商',
		isIf:'true',
		fit:true,
		method:'post',
		params:params,
		href:'<c:url value="/views/jsp/customer/salesman/salesman_buyer_list.jsp"/>',
		width:800
	}); 
}
$("#s_loc").LocationSelect({
	data:"<c:url value='/js/plug/area/areas.json' />"
});
//导出
function initStoreOutCheckTableExcel(){
	loadExcelCallBack('<c:url value="/salesman/searchPageSalesmanExcel.do"/>',getParams());
} 	
</script>
